package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;

public abstract class SingleFragmentActivity extends BaseVolleyActivity {
  protected static final String TAG = "FragmentActivity";
  Fragment fragment;
  private Toolbar mToolBar;

  /**
   * 是否遮挡内容
   */
  //    protected boolean isOverLay() {
  //        return true;
  //    }
  protected abstract Fragment createFragment();

  protected int getLayoutResId() {
    return R.layout.activity_fragment;
  }

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(getLayoutResId());

    FragmentManager fm = getSupportFragmentManager();
    fragment = fm.findFragmentById(R.id.fragmentContainer);
    if (fragment == null) {
      fragment = createFragment();
      fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit();
    }
    mToolBar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolBar != null) {
      mToolBar.setTitle(R.string.app_name);
    }

    //        if (Build.VERSION.SDK_INT >= 19) {
    //            if (isOverLay()) {
    //
    //                View layout = findViewById(R.id.appbar);
    //                MyUtils.setPaddingTop(layout, MyUtils.getStatusBarHeight(this));
    //            } else {
    //                View root = findViewById(R.id.container_root);
    //                //root.setBackgroundResource(R.color.primary);
    //                Window window = getWindow();
    //                //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏
    //                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    //                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //                //需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色
    //                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    //                //设置状态栏颜色
    //                    window.setStatusBarColor(getResources().getColor(R.color.primary));
    //                }
    //                MyUtils.setFitWindow(root);
    //            }
    //        }

    setSupportActionBar(mToolBar);
  }

  protected Toolbar getToolBar() {
    return mToolBar;
  }
}
